package com.example.hms.service.servicelmpl;

import com.example.hms.entity.LiveRecords;
import com.example.hms.dao.LiveRecordsDao;
import com.example.hms.service.LiveRecordsService;
import com.example.hms.util.Result;
import com.example.hms.util.ResultSubmit;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.READ_COMMITTED,rollbackFor = Exception.class)
public class LiveRecordsServiceImpl implements LiveRecordsService {
    @Resource
    private LiveRecordsDao liveRecordsDao;

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public Result selectAllLiveRecords(String roomNumber, String customerName, String identificationCard) {
        List<LiveRecords> liveRecordsList = liveRecordsDao.selectAllLiveRecords(roomNumber, customerName, identificationCard);
        return ResultSubmit.success(liveRecordsList);
    }

    @Override
    public int insert(LiveRecords liveRecords) {
        liveRecords.setDataUpdateTime(format.format(new Date()));
        liveRecords.setLiveRecordsId(Math.abs((int) System.currentTimeMillis()));
        liveRecords.setDeleteIdentity("未删除");
        int insert1 = liveRecordsDao.insert(liveRecords);
        return insert1;
    }
}
